package _0470_Implement_Rand0_Using_Rand7;

import java.util.Random;

/**
 * Date: 2021/9/5 13:48
 * 执行用时：6 ms, 在所有 Java 提交中击败了64.11%的用户
 * 内存消耗：43.4 MB, 在所有 Java 提交中击败了61.14%的用户
 */
public class Solution {

    public static final Random r = new Random();

    private int rand7() {  // 生成[1, 7]之间的随机数
        return r.nextInt(7) + 1;
    }

    public int rand10() {
        int t = (rand7() - 1) * 7 + rand7();
        if (t > 40) t = rand10();
        return (t - 1) % 10 + 1;
    }

    public static void main(String[] args) {

        Solution t = new Solution();
        for (int i = 0; i < 10; i++) {
            System.out.println(t.rand10());
        }
    }
}
